package main

import (
	"fmt"
	"os"
	codecs "sanguo/codec/cs"
	"sanguo/node/client/dispatcher"
	"sanguo/node/client/login"
	cs_msg "sanguo/protocol/cs/message"

	"github.com/sniperHW/kendynet"
)

func main() {

	if len(os.Args) < 3 {
		fmt.Printf("usage login userID addr\n")
		return
	}

	userID := os.Args[1]
	addr := os.Args[2]

	login.Login(userID, addr, func(session kendynet.StreamSession, d *dispatcher.Dispatcher, msg *codecs.Message, err error) {
		if nil != err {
			fmt.Println(err)
		} else {
			gameLoginToC := msg.GetData().(*cs_msg.GameLoginToC)
			fmt.Println(gameLoginToC)
		}
		d.Register(&cs_msg.UpdatePosToC{}, false, func(args []interface{}) {
			resp := args[1].(*codecs.Message).GetData().(*cs_msg.UpdatePosToC)
			kendynet.Infoln("read", resp)
		})
	})

	sigStop := make(chan bool)
	_, _ = <-sigStop
}
